/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bgu.sonar.util.collections;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

/**
 *
 * @author bennyl
 */
public class ImmutableList<T> implements List<T> {

    private List<T> wrapee;

    public ImmutableList(List<T> wrapee) {
        this.wrapee = wrapee;
    }

    @Override
    public int size() {
        return wrapee.size();
    }

    @Override
    public boolean isEmpty() {
        return wrapee.isEmpty();
    }

    @Override
    public boolean contains(Object o) {
        return wrapee.contains(o);
    }

    @Override
    public Iterator<T> iterator() {
        final Iterator<T> i = wrapee.iterator();
        return new Iterator<T>() {
            @Override
            public boolean hasNext() {
                return i.hasNext();
            }

            @Override
            public T next() {
                return i.next();
            }

            @Override
            public void remove() {
                throw new UnsupportedOperationException("Not supported.");
            }
        };
    }

    @Override
    public Object[] toArray() {
        return wrapee.toArray();
    }

    @Override
    public <T> T[] toArray(T[] a) {
        return wrapee.toArray(a);
    }

    @Override
    public boolean add(T e) {
        throw new UnsupportedOperationException("Not supported.");
    }

    @Override
    public boolean remove(Object o) {
        throw new UnsupportedOperationException("Not supported.");
    }

    @Override
    public boolean containsAll(Collection<?> c) {
        return wrapee.containsAll(c);
    }

    @Override
    public boolean addAll(Collection<? extends T> c) {
        throw new UnsupportedOperationException("Not supported.");
    }

    @Override
    public boolean addAll(int index, Collection<? extends T> c) {
        throw new UnsupportedOperationException("Not supported.");
    }

    @Override
    public boolean removeAll(Collection<?> c) {
        throw new UnsupportedOperationException("Not supported.");
    }

    @Override
    public boolean retainAll(Collection<?> c) {
        throw new UnsupportedOperationException("Not supported.");
    }

    @Override
    public void clear() {
        throw new UnsupportedOperationException("Not supported.");
    }

    @Override
    public boolean equals(Object o) {
        return wrapee.equals(o);
    }

    @Override
    public int hashCode() {
        return wrapee.hashCode();
    }

    @Override
    public T get(int index) {
        return wrapee.get(index);
    }

    @Override
    public T set(int index, T element) {
        throw new UnsupportedOperationException("Not supported.");
    }

    @Override
    public void add(int index, T element) {
        throw new UnsupportedOperationException("Not supported.");
    }

    @Override
    public T remove(int index) {
        throw new UnsupportedOperationException("Not supported.");
    }

    @Override
    public int indexOf(Object o) {
        return wrapee.indexOf(o);
    }

    @Override
    public int lastIndexOf(Object o) {
        return wrapee.lastIndexOf(o);
    }

    @Override
    public ListIterator<T> listIterator() {
        return listIterator(0);
    }

    @Override
    public ListIterator<T> listIterator(int index) {
        final ListIterator<T> i = wrapee.listIterator(index);
        return new ListIterator<T>() {
            @Override
            public boolean hasNext() {
                return i.hasNext();
            }

            @Override
            public T next() {
                return i.next();
            }

            @Override
            public boolean hasPrevious() {
                return i.hasPrevious();
            }

            @Override
            public T previous() {
                return i.previous();
            }

            @Override
            public int nextIndex() {
                return i.nextIndex();
            }

            @Override
            public int previousIndex() {
                return i.previousIndex();
            }

            @Override
            public void remove() {
                throw new UnsupportedOperationException("Not supported");
            }

            @Override
            public void set(T e) {
                throw new UnsupportedOperationException("Not supported");
            }

            @Override
            public void add(T e) {
                throw new UnsupportedOperationException("Not supported");
            }
        };
    }

    @Override
    public ImmutableList<T> subList(int fromIndex, int toIndex) {
        return new ImmutableList<>(wrapee.subList(fromIndex, toIndex));
    }
}
